package bancosys.tec.utils.math;

import java.math.MathContext;
import java.math.RoundingMode;

/**
 * @created May 18, 2007
 * @author Gustavo Almeida
 * @see MathContext
 */
public class RoundingContext {
    /**
     * Precisao default: MathContext.UNLIMITED.getPrecision().
     */
    public static final int DEFAULT_PRECISION = MathContext.UNLIMITED.getPrecision();

    private RoundingMode roundingMode;

    private int scale;

    private int precision;

    /**
     * Construtor, utiliza precision = MathContext.UNLIMITED.getPrecision().
     * 
     * @param roundingMode estrategia de arredondamento.
     * @param scale escala
     */
    public RoundingContext(RoundingMode roundingMode, int scale) {
        this(roundingMode, scale, DEFAULT_PRECISION);
    }

    /**
     * Construtor.
     * 
     * @param roundingMode estrategia de arredondamento.
     * @param scale escala.
     * @param precision precisao.
     */
    public RoundingContext(RoundingMode roundingMode, int scale, int precision) {
        this.precision = precision;
        this.scale = scale;
        this.roundingMode = roundingMode;
    }

    /**
     * Devovle o precision.
     * 
     * @return o precision.
     */
    public int getPrecision() {
        return this.precision;
    }

    /**
     * Define o precision.
     * 
     * @param precision O precision a ser definido.
     */
    public void setPrecision(int precision) {
        this.precision = precision;
    }

    /**
     * Devolve o roundingMode.
     * 
     * @return o roundingMode.
     */
    public RoundingMode getRoundingMode() {
        return this.roundingMode;
    }

    /**
     * Define o roundingMode.
     * 
     * @param roundingMode O roundingMode a ser definido.
     */
    public void setRoundingMode(RoundingMode roundingMode) {
        this.roundingMode = roundingMode;
    }

    /**
     * Devolve o scale.
     * 
     * @return o scale.
     */
    public int getScale() {
        return this.scale;
    }

    /**
     * Define o scale.
     * 
     * @param scale O scale a ser definido.
     */
    public void setScale(int scale) {
        this.scale = scale;
    }

    /**
     * Devolve um mathContext com o precision e roundingMode definidos.
     * 
     * @return um mathContext com o precision e roundingMode definidos.
     */
    public MathContext getMathContext() {
        return new MathContext(this.precision, this.roundingMode);
    }
}
